package com.tourlaid.mamagerment.action.pc

import com.tourlaid.mamagerment.ao.pc.GoodsAo
import com.tourlaid.mamagerment.entity.ResponseData
import com.tourlaid.mamagerment.vo.GoodsVo
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.bind.annotation.RestController

/**
 * Created by xiaoyongge on 2017/7/20.
 */
@RestController
@RequestMapping("/tld/admin/goods")
class GoodsAction {

    @Autowired
    private val goodsAo: GoodsAo? = null

    @RequestMapping("/list.json")
    fun list(@RequestParam(defaultValue = "1") pageNo: Int,
             @RequestParam(defaultValue = "10") pageSize: Int,
             callback: String): String {
        val ResponseData = goodsAo!!.list(pageNo, pageSize);
        return ResponseData.toJson(callback)
    }

    @RequestMapping("/insert.json")
    fun insert(goodsName: String?, controlNo: String?, callback: String): String {
        goodsAo!!.insert(goodsName, controlNo);
        return ResponseData<String>().toJson(callback)
    }

    @RequestMapping("/detail.json")
    fun detail(goodsId: Long): ResponseData<GoodsVo> {
        var goodsVo = goodsAo!!.detail(goodsId);
        return ResponseData(goodsVo)
    }

    @RequestMapping("/update.json")
    fun update(goodsId: Long?, goodsName: String?, controlNo: String?, callback: String): String {
        goodsAo!!.update(goodsId, goodsName, controlNo);
        return ResponseData<String>().toJson(callback)
    }

    @RequestMapping("/delete.json")
    fun delete(goodsId: Long?, callback: String): String {
        goodsAo!!.delete(goodsId);
        return ResponseData<String>().toJson(callback)
    }
}